#include "base.h"
#include <vcclr.h>
#pragma once

int ReadBattleList(HANDLE h, int base){
	int ret = 0;

	for(int i = 0; i < 250; i++){
		int id;
		int selfid;
		ReadProcessMemory(h, (LPVOID)(base + 5996776 + (0xC4 * i)), &id, 4, 0);
		ReadProcessMemory(h, (LPVOID)(base + 5644340), &selfid, 4, 0);
		ret = i;
		if(id == selfid)
			break;
	}

	return ret;
}

int outfits[] = {0, 128, 129, 130, 131, 132, 133, 134, 143, 144, 145, 146, 151, 152, 153, 154, 251, 268, 273, 278, 289, 325, 328, 335, 367, 430, 432, 463, 465, 472, 512, 516, 541, 574, 577/* < Male .. Female > */, 136, 137, 138, 139, 140, 141, 142, 147, 148, 149, 150, 155, 156, 157, 158, 252, 269, 270, 279, 288, 324, 329, 336, 366, 431, 433, 464, 466, 471, 513, 514, 542, 575, 578};
int mounts[] = {0, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 387, 388, 389, 390, 392, 401, 402, 405, 406, 421, 426, 427, 437, 438, 447, 450, 502, 503, 506, 515, 521, 522, 526, 546, 547, 548, 559, 571, 572, 580};

namespace fakeaddon {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Summary for Form1
	///
	/// WARNING: If you change the name of this class, you will need to change the
	///          'Resource File Name' property for the managed resource compiler tool
	///          associated with all .resx files this class depends on.  Otherwise,
	///          the designers will not be able to interact properly with localized
	///          resources associated with this form.
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: Add the constructor code here
			//
		}

	protected:
		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	protected: 
	private: System::Windows::Forms::CheckBox^  checkBox1;
	private: System::Windows::Forms::CheckBox^  checkBox2;
	private: System::Windows::Forms::Label^  label1;

	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::ListBox^  listBox1;
	private: System::Windows::Forms::ListBox^  listBox2;
	private: System::Windows::Forms::Label^  label3;





























	private:
		/// <summary>
		/// Required designer variable.
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		void InitializeComponent(void)
		{
			this->button1 = (gcnew System::Windows::Forms::Button());
			this->checkBox1 = (gcnew System::Windows::Forms::CheckBox());
			this->checkBox2 = (gcnew System::Windows::Forms::CheckBox());
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->label2 = (gcnew System::Windows::Forms::Label());
			this->listBox1 = (gcnew System::Windows::Forms::ListBox());
			this->listBox2 = (gcnew System::Windows::Forms::ListBox());
			this->label3 = (gcnew System::Windows::Forms::Label());
			this->SuspendLayout();
			// 
			// button1
			// 
			this->button1->Location = System::Drawing::Point(139, 294);
			this->button1->Name = L"button1";
			this->button1->Size = System::Drawing::Size(75, 23);
			this->button1->TabIndex = 0;
			this->button1->Text = L"Update";
			this->button1->UseVisualStyleBackColor = true;
			this->button1->Click += gcnew System::EventHandler(this, &Form1::button1_Click);
			// 
			// checkBox1
			// 
			this->checkBox1->AutoSize = true;
			this->checkBox1->Location = System::Drawing::Point(12, 12);
			this->checkBox1->Name = L"checkBox1";
			this->checkBox1->Size = System::Drawing::Size(73, 17);
			this->checkBox1->TabIndex = 1;
			this->checkBox1->Text = L"Addon #1";
			this->checkBox1->UseVisualStyleBackColor = true;
			// 
			// checkBox2
			// 
			this->checkBox2->AutoSize = true;
			this->checkBox2->Location = System::Drawing::Point(12, 35);
			this->checkBox2->Name = L"checkBox2";
			this->checkBox2->Size = System::Drawing::Size(73, 17);
			this->checkBox2->TabIndex = 2;
			this->checkBox2->Text = L"Addon #2";
			this->checkBox2->UseVisualStyleBackColor = true;
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->BackColor = System::Drawing::Color::Transparent;
			this->label1->Location = System::Drawing::Point(9, 307);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(95, 13);
			this->label1->TabIndex = 3;
			this->label1->Text = L"Milice (xB1N4RYx)";
			// 
			// label2
			// 
			this->label2->AutoSize = true;
			this->label2->Location = System::Drawing::Point(12, 57);
			this->label2->Name = L"label2";
			this->label2->Size = System::Drawing::Size(40, 13);
			this->label2->TabIndex = 5;
			this->label2->Text = L"Outfits:";
			// 
			// listBox1
			// 
			this->listBox1->FormattingEnabled = true;
			this->listBox1->Items->AddRange(gcnew cli::array< System::Object^  >(69) {L"Default", L"Citizen (Male)", L"Hunter (Male)", 
				L"Mage (Male)", L"Knight (Male)", L"Nobleman (Male)", L"Summoner (Male)", L"Warrior (Male)", L"Barbarian (Male)", L"Druid (Male)", 
				L"Wizard (Male)", L"Oriental (Male)", L"Pirate (Male)", L"Assassin (Male)", L"Beggar (Male)", L"Shaman (Male)", L"Norseman (Male)", 
				L"Nightmare (Male)", L"Jester (Male)", L"Brotherhood (Male)", L"Demonhunter (Male)", L"Yalaharian (Male)", L"Husband (Male)", 
				L"Warmaster (Male)", L"Wayfarer (Male)", L"Afflicted (Male)", L"Elemetantalist (Male)", L"Deepling (Male)", L"Insectoid (Male)", 
				L"Entrepreneur (Male)", L"Crystal Warlord (Male)", L"Soil Guardian (Male)", L"Demon (Male)", L"Cave Explorer (Male)", L"Dream Warden (Male)", 
				L"Citizen (Female)", L"Hunter (Female)", L"Mage (Female)", L"Knight (Female)", L"Noblewoman (Female)", L"Summoner (Female)", 
				L"Warrior (Female)", L"Barbarian (Female)", L"Druid (Female)", L"Wizard (Female)", L"Oriental (Female)", L"Pirate (Female)", 
				L"Assassin (Female)", L"Beggar (Female)", L"Shaman (Female)", L"Norsewoman (Female)", L"Nightmare (Female)", L"Jester (Female)", 
				L"Brotherhood (Female)", L"Demonhunter (Female)", L"Yalaharian (Female)", L"Wife (Female)", L"Warmaster (Female)", L"Wayfarer (Female)", 
				L"Afflicted (Female)", L"Elemetantalist (Female)", L"Deepling (Female)", L"Insectoid (Female)", L"Entrepreneur (Female)", L"Crystal Warlord (Female)", 
				L"Soil Guardian (Female)", L"Demon (Female)", L"Cave Explorer (Female)", L"Dream Warden (Female)"});
			this->listBox1->Location = System::Drawing::Point(12, 73);
			this->listBox1->Name = L"listBox1";
			this->listBox1->Size = System::Drawing::Size(202, 95);
			this->listBox1->TabIndex = 6;
			// 
			// listBox2
			// 
			this->listBox2->FormattingEnabled = true;
			this->listBox2->Items->AddRange(gcnew cli::array< System::Object^  >(43) {L"None", L"Widow Queen", L"Racing Bird", L"War Bear", 
				L"Black Sheep", L"Midnight Panther", L"Draptor", L"Titanica", L"Tin Lizzard", L"Blazebringer", L"Rapid Boar", L"Stampor", L"Undead Cavebear", 
				L"Donkey", L"Tiger Slug", L"Uniwheel", L"Crystal Wolf", L"Brown War Horse", L"Kingly Deer", L"Tamed Panda", L"Dromedary", L"King Scorpion", 
				L"Rented Horse (Brown)", L"Armoured War Horse", L"Shadow Draptor", L"Rented Horse (Gray)", L"Rented Hourse (Brown2)", L"Ladybug", 
				L"Manta", L"Ironblight", L"Magma Crawler", L"Dragonling", L"Gnarlhound", L"Crimson Ray", L"Steelbeak", L"Water Buffalo", L"Armoured Scorption", 
				L"Armoured Dragonling", L"Ursagrodon", L"Hellgrip", L"Lion", L"Golden Lion", L"Shock Head"});
			this->listBox2->Location = System::Drawing::Point(12, 187);
			this->listBox2->Name = L"listBox2";
			this->listBox2->Size = System::Drawing::Size(202, 95);
			this->listBox2->TabIndex = 7;
			// 
			// label3
			// 
			this->label3->AutoSize = true;
			this->label3->Location = System::Drawing::Point(12, 171);
			this->label3->Name = L"label3";
			this->label3->Size = System::Drawing::Size(45, 13);
			this->label3->TabIndex = 8;
			this->label3->Text = L"Mounts:";
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->BackColor = System::Drawing::Color::White;
			this->ClientSize = System::Drawing::Size(226, 329);
			this->Controls->Add(this->label3);
			this->Controls->Add(this->listBox2);
			this->Controls->Add(this->listBox1);
			this->Controls->Add(this->label2);
			this->Controls->Add(this->label1);
			this->Controls->Add(this->checkBox2);
			this->Controls->Add(this->checkBox1);
			this->Controls->Add(this->button1);
			this->FormBorderStyle = System::Windows::Forms::FormBorderStyle::FixedToolWindow;
			this->Name = L"Form1";
			this->Text = L"Fake Outfit / Mount 10.38";
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
				 int addons = 0;
				 if(checkBox1->Checked)
					 addons++;
				 if(checkBox2->Checked)
					addons += 2;

				 int SelectedOutfit = listBox1->SelectedIndex;
				 if(SelectedOutfit < 0)
					 SelectedOutfit = 0;
				 int SelectedMount = listBox2->SelectedIndex;
				 if(SelectedMount < 0)
					 SelectedMount = 0;
				
				 HWND windzw = FindWindow(L"TibiaClient",0);
					
				 if(windzw){
					DWORD PID;
					GetWindowThreadProcessId(windzw, &PID);
					HANDLE Tibia = OpenProcess(PROCESS_ALL_ACCESS, false, (DWORD)PID);

					int base = (int)GetRemoteBase(PID, "Tibia.exe");

					int addon = base + 5996892 + (ReadBattleList(Tibia, base) * 0xC4);
					int outfit = base + 5996872 + (ReadBattleList(Tibia, base) * 0xC4);
					int mount = base + 5996896 + (ReadBattleList(Tibia, base) * 0xC4);
					
					WriteProcessMemory(Tibia, (LPVOID)addon, &addons, 1, NULL);
					
					int oldOutfit;
					ReadProcessMemory(Tibia, (LPVOID)outfit, &oldOutfit, 4, NULL);
					outfits[0] = oldOutfit;
					int newOutfit = outfits[SelectedOutfit];
					WriteProcessMemory(Tibia, (LPVOID)outfit, &newOutfit, 4, NULL);
					
					int newMount = mounts[SelectedMount];
					WriteProcessMemory(Tibia, (LPVOID)mount, &newMount, 4, NULL);
					
					CloseHandle(Tibia);
				 }
			 }
};
}

